package yaner.hotel.manager.resource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yaner.hotel.manager.common.dto.role.RoleAddDto;
import yaner.hotel.manager.common.dto.role.RoleDto;
import yaner.hotel.manager.common.dto.role.RoleUpdateDto;
import yaner.hotel.manager.common.vo.ResponseVo;
import yaner.hotel.manager.common.vo.RoleVo;
import yaner.hotel.manager.resource.service.IRoleService;

import java.util.List;

/**
 * @Author kf-leig
 * @Description: 角色管理
 * @Date 2024年05月22日11:31:00
 */
@Slf4j
@RestController
public class RoleController {
    private final IRoleService roleService;
    public RoleController(IRoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping("/role-list")
    public ResponseVo<List<RoleVo>> roleList(@RequestBody RoleDto roleDto){
        List<RoleVo> roleVos = roleService.roleList(roleDto);
        return ResponseVo.success(roleVos);
    }

    @PostMapping("/role-page")
    public ResponseVo<Page<RoleVo>> rolePage(@RequestBody RoleDto roleDto){
        Page<RoleVo> roleVoPage = roleService.rolePage(roleDto);
        return ResponseVo.success(roleVoPage);
    }

    @GetMapping("get-role-info")
    public ResponseVo<RoleVo> getRoleInfo(@RequestParam("roleId") String roleId){
        RoleVo info = roleService.getRoleInfo(roleId);
        return ResponseVo.success(info);
    }

    @PostMapping("add-role-info")
    public ResponseVo<String> addRoleInfo(@RequestBody RoleAddDto roleAddDto){
        String s = roleService.addRoleInfo(roleAddDto);
        return ResponseVo.success(s);
    }

    @PostMapping("update-role-info")
    public ResponseVo<String> updateRoleInfo(@RequestBody RoleUpdateDto roleUpdateDto){
        String s = roleService.updateRoleInfo(roleUpdateDto);
        return ResponseVo.success(s);
    }

    @DeleteMapping("delete-role-info")
    public ResponseVo<String> deleteRoleInfo(@RequestParam("roleId") String roleId){
        String s = roleService.deleteRoleInfo(roleId);
        return ResponseVo.success(s);
    }
}
